package org.smarthings.things.commons.utils;

public class PaginationUtils {

	// size > 0 , non empty list!

	public static int calculateFirstPageSize(int offset, int limit, int size) {
		return limit > size ? size : limit;
	}

	public static int calculateLastPageSize(int offset, int limit, int size) {
		int last = size - ((size / limit) * limit);
		if (last == 0) {
			last = size - limit;
		}
		return last;
	}

	public static int calculateNextPageOffset(int offset, int limit, int size) {
		return offset + limit >= size ? size : offset + limit;
	}

	public static int calculatePreviousPageOffset(int offset, int limit, int size) {
		return offset - limit <= 0 ? 0 : offset - limit;
	}

}
